package api

import (
	"2212b/2212ay1/api/handler"
	"2212b/2212ay1/api/middleware"
	"2212b/2212ay1/consts"
	"github.com/gin-gonic/gin"
	jwt "github.com/golangblogs/gojwt"
)

func ToadRouter(r *gin.Engine) {
	r.Use(middleware.CQRS())
	api := r.Group("/api")
	{
		user := api.Group("user")
		{
			user.POST("register", handler.Register)
			user.POST("sendSms", handler.SendSms)
			user.POST("login", handler.Login)
			user.Use(jwt.JWTAuth(consts.JWT_KEY))
			user.POST("/get/token", handler.GetUserToken) //更新token
			user.POST("/get/list", handler.GetUserList)   //用户列表
			user.POST("/get/show", handler.GetUserShow)   //用户详情
		}
		file := api.Group("file")
		{
			file.POST("upload/file", handler.UploadFile) //文件上传接口
		}
		chat := api.Group("chat")
		{
			user.Use(jwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
		}
		order := api.Group("order")
		{
			order.Use(jwt.JWTAuth(consts.JWT_KEY))
			order.POST("recharge", handler.RechargeOrder)
			order.POST("buy", handler.BuyOrder)
			order.GET("list", handler.GetOrderList)
		}
		damu := api.Group("damu")
		{
			damu.Use(jwt.JWTAuth(consts.JWT_KEY))
			damu.POST("/send", handler.SendDamu) //14.	实时弹幕发布
		}
	}
}
